#ifndef V4L2API_H
#define V4L2API_H

#include <QObject>
#include <QImage>

extern "C" {
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <linux/videodev2.h>
};

class V4l2Api : public QObject
{
    Q_OBJECT
public:
    explicit V4l2Api(const char* deviceName, QObject *parent = nullptr);
    ~V4l2Api();

    bool start();
    void stop();
    void destory();

    void get_frame(char* buffer, int *size);
    bool yuv422torgb24(unsigned char *buffer, unsigned char *rgbdata, int w, int h);

signals:
    void errorOccurred(const QString &message);

private:
    int m_fd;
    bool m_isRunning;
    unsigned char* m_mptr[4];
    unsigned int m_size[4];
};

#endif // V4L2API_H
